const http = require("http"),
    zlib = require("zlib"),
    fs = require("fs"),
    filePath = "./extra/index.html";

const server = http.createServer((req, res) => {
    const acceptEncoding = req.headers["accept-encoding"];
    let gzip;
    if (acceptEncoding.indexOf("gzip") !== -1) {
        gzip = zlib.createGzip();

        res.writeHead(200, {
            "Contend-Encoding": "gzip",
        });

        fs.createReadStream(filePath).pipe(gzip).pipe(res);
    } else {
        fs.createReadStream(filePath).pipe(res);
    }
});

server.listen(3002);
